package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.entity.Category;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CategoryMapper {

    //分页查询
    Page<Category> pageQuery(Category category);

    //更新分类信息
    void updateCategory(Category category);

    //根据类型查询分类
    @Select("select id,name from category where type=#{type}")
    List<Category> getCategoryByType(String type);

    //新增分类
    @Insert("insert into category " +
            "(type, name, sort, status, create_time, update_time, create_user, update_user)" +
            " VALUE (#{type},#{name},#{sort},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser})")
    void addCategory(Category category);

    //查询菜品分类下是否包含菜品
    @Select("select 1 from dish where category_id=#{id} limit 1;")
    Integer categoryContainsDish(Long id);

    //根据id删除分类
    @Delete("delete from category where id=#{id}")
    void deleteCategory(Long id);

    //根据id查询名称
    @Select("select name from category where id = #{categoryId}")
    String selectNameById(Long categoryId);

    //根据类型查询分类
    @Select("select * from category where type=#{type}")
    List<Category> list(String type);

    //查询所有分类
    @Select("select * from category")
    List<Category> listAll();
}
